#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main()
{
	int t;
	scanf("%d", &t);

	int i = 1;
	int j;
	int N;
	int tmp;
	for (i; i <= t; i++)
	{
		scanf("%d", &N);
		for (j = 1; j <= N; j++)
		{
			if (j % 7 == 0)
			{
				printf("%d ", j);
				continue;
			}

			tmp = j;
			while (tmp > 0)
			{
				if (tmp % 10 == 7)
				{
					printf("%d ", j);
					break;
				}
				tmp = tmp / 10;
			}
		}
		printf("\n");
	}

	return 0;
}